package com.lms.busi.common.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lms.busi.common.res.SysCommonCodeRes;
import com.lms.common.entity.SysCommonCode;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface SysCommonCodeMapper extends BaseMapper<SysCommonCode> {
    SysCommonCode getByCode(@Param("categoryCode") String categoryCode, @Param("code") String code);

    IPage<SysCommonCodeRes> query(Page<?> page, @Param("params") Map<String, Object> p);

    @Select("select IFNULL(max(sort), 0) from sys_common_code where category_code = #{categoryCode}")
    int selectMaxSortByCategoryCode(@Param("categoryCode") String categoryCode);

    @Select("select category_name, category_code from sys_common_code group by category_code, category_name")
    List<SysCommonCode> selectCategory();
}
